package com.sn.campus.controller;


import com.alibaba.fastjson.JSONObject;
import com.sn.campus.entity.Operat;
import com.sn.campus.model.ResponseResult;
import com.sn.campus.model.ResultEnum;
import com.sn.campus.service.OperationService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @ProjectName: springboot_socket
 * @Package: com.sn.socket.controller
 * @ClassName: ${CLASS_NAME}
 * @Author: xiahuihui
 * @Description: ${description}
 * @Date: 2020/5/12 0012 9:53
 * @Version: 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("opera")
public class OperationController {


    @Resource
    private OperationService operationService;

    @PostMapping("device")
    public ResponseResult<?> timelyDevice(@RequestBody Operat operat) {
        ResponseResult<?> result = new ResponseResult<>();

        operationService.timelyTask(operat);

        result.setResultEnum(ResultEnum.RESULT_SUCCESS);
        return result;
    }

    @GetMapping("getindex")
    public String getindex() {
        HashMap<String, List> retIndexData = new HashMap<>(7);
        retIndexData.put("schools", operationService.getIndexCommunities());
        retIndexData.put("clockstat", operationService.getIndexClockStat());
        retIndexData.put("top5", operationService.getIndexTop5());
        retIndexData.put("top10", operationService.getIndexTop10());
        retIndexData.put("devicestat", operationService.getIndexDeviceStat());
        retIndexData.put("totalstat", operationService.getIndextotalstat());
        retIndexData.put("sosdevice", operationService.getIndexSosStat());
//        return retIndexData;
        return "callback" + "(" + JSONObject.toJSONString(retIndexData) + ")";
    }

    @GetMapping("getSchoolData")
    public String getSchoolData(@RequestParam String commnunityno_) {
//        String commnunityno_ = params.get("commnunityno_").toString();
        HashMap<String, List> retIndexData = new HashMap<>(4);
        retIndexData.put("attendances", operationService.getSchoolAttends(commnunityno_));
        retIndexData.put("temperatures", operationService.getSchoolTemps(commnunityno_));
        retIndexData.put("monitorvideo", operationService.getSchoolMonitorVideo(commnunityno_));
        retIndexData.put("sosvideo", operationService.getSchoolSosVideo(commnunityno_));

//        return retIndexData;
        return "callback" + "(" + JSONObject.toJSONString(retIndexData) + ")";
    }
}
